package custom.cards;

import java.io.Serializable;


public class Card implements Serializable
{


	private static final long serialVersionUID = 1L;
	
 /**
  * the cards number
  */
	public final CardNumber number;
	/**
	 * the cards suite
	 */
	public final CardSuite Suite;

	/**
	 * Used to determine if clicked or just dragged
	 */
	public boolean actuallyDragged = false;
	public boolean clickedObect = false;
	boolean cardShowing;


	public Card(CardNumber num, CardSuite suite, boolean showFront)
	{

		this.number = num;
		this.Suite = suite;
		cardShowing = showFront;

	}
	

	
	public Card(String toStringVersion, boolean showFront)
	{

		String[] split = toStringVersion.split(" ");
		
		if(split.length == 4)
		{
			String number = split[1];
			String suit = split[3];
			
			this.number = CardNumber.values()[Integer.parseInt(number)];
			this.Suite = CardSuite.values()[Integer.parseInt(suit)];
			

			cardShowing = showFront;

			

		}
		else
		{
			this.number = null;
			this.Suite = null;

		}
		
		
		
		
		
	}
	
	 public boolean equals(Object obj) 
	 {
	        if (obj == null)
	            return false;
	        if (obj == this)
	            return true;
	        if (obj.getClass() != getClass())
	            return false;

	        if(this == null && obj != null)
	        {
	        	return false;
	        }
	        
	        Card c = (Card) obj;
	        
	        if(c.number == this.number && c.Suite == this.Suite)
	        {
	        	return true;
	        }
	        else
	        {
	        	return false;
	        }
	    }
	
	public String toNumberString()
	{
		
		return String.format("The %d of %d", this.number.ordinal(), this.Suite.ordinal());
	}


	@Override 
	public String toString()
	{
			return String.format("The %s of %s", this.number, this.Suite);
	}

	public enum CardSuite
	{
		Hearts,
		Clubs,
		Spades,
		Diamonds	
	}
	
	public enum CardNumber
	{
		Two,
		Three,
		Four,
		Five,
		Six,
		Seven,
		Eight,
		Nine,
		Ten,
		Jack,
		Queen,
		King,
		Ace,
		Joker
	}
}

